﻿// DlgPrinterAdvCheck.cpp : 实现文件
//

#include "stdafx.h"
#include "POSCheck.h"
#include "DlgPrinterAdvCheck.h"
#include "afxdialogex.h"
#include "Printer.h"

// CDlgPrinterAdvCheck 对话框

IMPLEMENT_DYNAMIC(CDlgPrinterAdvCheck, CDialogEx)

CDlgPrinterAdvCheck::CDlgPrinterAdvCheck(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgPrinterAdvCheck::IDD, pParent)
{
    m_pPrinter = NULL;
}

CDlgPrinterAdvCheck::~CDlgPrinterAdvCheck()
{
    m_pPrinter = NULL;
}

void CDlgPrinterAdvCheck::RegistPrinter(CPOSPrinter *pPrinter)
{
    m_pPrinter = pPrinter;
//    if(NULL != pPrinter) m_pPrinter->Initialize();
}

void CDlgPrinterAdvCheck::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDlgPrinterAdvCheck, CDialogEx)
    ON_BN_CLICKED(IDOK, &CDlgPrinterAdvCheck::OnBnClickedOk)
    ON_BN_CLICKED(IDC_BTN_CUT, &CDlgPrinterAdvCheck::OnBnClickedBtnCut)
    ON_BN_CLICKED(IDC_BTN_ADV_PRINT, &CDlgPrinterAdvCheck::OnBnClickedBtnAdvPrint)
    ON_BN_CLICKED(IDC_CHK_UNDERLINE, &CDlgPrinterAdvCheck::OnBnClickedChkUnderline)
    ON_BN_CLICKED(IDC_CHK_BOLD, &CDlgPrinterAdvCheck::OnBnClickedChkBold)
END_MESSAGE_MAP()


// CDlgPrinterAdvCheck 消息处理程序



void CDlgPrinterAdvCheck::OnBnClickedOk()
{

    CDialogEx::OnOK();
}


BOOL CDlgPrinterAdvCheck::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    

    return TRUE;  
}



void CDlgPrinterAdvCheck::OnBnClickedBtnCut()
{
    if(NULL != m_pPrinter)
    {
        m_pPrinter->CutPaper(0);
    }
}


void CDlgPrinterAdvCheck::OnBnClickedBtnAdvPrint()
{
    if(NULL == m_pPrinter)
        return;

    CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT_TEXT);
    if(NULL == pEdit) return;

    CString strText;
    pEdit->GetWindowText(strText);

    m_pPrinter->Print(strText, strText.GetLength()*sizeof(TCHAR));
    //GetDlgItem(IDC_EDIT_TEXT)
}


void CDlgPrinterAdvCheck::OnBnClickedChkUnderline()
{
    if(NULL == m_pPrinter) return;

    CButton *pBtn = (CButton*)GetDlgItem(IDC_CHK_UNDERLINE);
    
    if(NULL == pBtn) return;

    if(BST_CHECKED == pBtn->GetCheck())
    {
        m_pPrinter->SetUnderline(1);
    }
    else
        m_pPrinter->SetUnderline(0);
}


void CDlgPrinterAdvCheck::OnBnClickedChkBold()
{
    if(NULL == m_pPrinter) return;

    CButton *pBtn = (CButton*)GetDlgItem(IDC_CHK_BOLD);

    if(NULL == pBtn) return;

    if(BST_CHECKED == pBtn->GetCheck())
    {
        m_pPrinter->EnableBold();
    }
    else
        m_pPrinter->EnableBold(0);
}
